// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    activeName: 0,
    list: [],

    amount: '',

    amount_finishi: '',

    amount_surplus: '',

    // more
    loading: false,
    allLoaded: false,
    goload: true,
    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function(options) {
    this.getData();
    this.getList();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function() {},

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function() {},

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function() {},

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function() {},

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function() {
    if (this.data.isLoadMore) {
      this.getMoreData(this.data.page);
    } else {
      console.log('没有更多数据');
    }
  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function() {},

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function() {},

  getData() {
    let urlStr = app.getNetAddresss('plugin.member-return.frontend.queue.index');
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          this.setData({
            amount: resdata.data.queue.amount,
            amount_finishi: resdata.data.queue.amount_finish,
            amount_surplus: resdata.data.queue.amount_surplus
          });
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },

  getList() {
    let urlStr = app.getNetAddresss('plugin.member-return.frontend.log.get-list');
    urlStr += '&page=' + this.data.page;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        let resdata = res.data;
        if (resdata.result === 1) {
          this.setData({
            list: resdata.data.data,
            total_page: resdataresdata.data.last_page
          });
        } else {
          wx.showToast({
            title: resdata.msg,
            icon: 'none'
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },

  gotoDetail(val) {
    let id = val.target.dataset.id || val.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageB/member/enterprise/RecordOfAwards/RecordOfAwards' + '?id=' + id

    });
  },
  getMoreData(page) {
    if (this.data.page == this.data.total_page) {
      return;
    }
    if (this.data.page >= this.data.total_page) {
      this.setData({
        loading: true,
        allLoaded: true
      });
      return;
    } else {
      let page = this.data.page + 1;
      this.setData({
        page
      });
      let urlStr = app.getNetAddresss('plugin.member-return.frontend.log.get-list');
      urlStr += '&page=' + this.data.page;
      app._getNetWork({
        url: urlStr,
        success: (res) => {
          let resdata = res.data;
          if (resdata.result === 1) {
            resdata.data = resdata.data.data;
            let list = this.data.list.concat(resdata.data.data);
            this.setData({
              loading: false,
              allLoaded: false,
              list
            });
          } else {
            wx.showToast({
              title: resdata.msg,
              icon: 'none'
            });
            let pages = this.data.page - 1;
            this.setData({
              page: pages,
              loading: true,
              allLoaded: true,
              isLoadMore: false
            });
            return;
          }
        },
        fail: function(res) {
          console.log(res);
        }
      });
    }
  }

});
